<?php

namespace App\Exceptions;

use Exception;
use Throwable;

class MemberException extends Exception
{
    public function __construct( $message = '', $code = 0, \Closure $callback = null )
    {
        // code int
        if( ! is_numeric( $code ) )
        {
            $code = 0;
        }

        parent::__construct( $message, $code );

        // 执行回调
        if( $callback )
        {
            $callback();
        }
    }

    public function render()
    {
        return response()->json( 
            [
                'code' => 0,
                'message' => 'success',
                'result' => [
                    'status' => 0 - $this->getCode(),
                    'message' => $this->getMessage()
                ]
            ]
        );
    }
}
